package cn.itcast.service.impl;

import cn.itcast.dao.DeliveryRepository;
import cn.itcast.dao.TransitRepository;
import cn.itcast.domain.transit.DeliveryInfo;
import cn.itcast.domain.transit.TransitInfo;
import cn.itcast.service.DeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DeliveryServiceImpl implements DeliveryService {
    @Autowired
    private DeliveryRepository deliveryRepository;
    @Autowired
    private TransitRepository transitRepository;
    @Override
    @Transactional
    public void save(String transitInfoId, DeliveryInfo deliveryInfo) {
        //获得持久化对象
         deliveryRepository.save(deliveryInfo);
        TransitInfo transitInfo = transitRepository.findOne(Integer.parseInt(transitInfoId));
        //关联持久化对象
        transitInfo.setDeliveryInfo(deliveryInfo);
        //更新数据
        transitInfo.setStatus("开始配送");
    }
}
